package com.ruoyi.project.pms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.db.pms.domain.PmsGoodsSpecification;
import com.ruoyi.db.pms.domain.query.PmsGoodsSpecificationQueryVo;
import com.ruoyi.project.pms.service.PmsGoodsSpecificationService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商品规格Controller
 *
 * @author ruoyi
 * @date 2020-04-21
 */
@Api(tags="pms管理：商品规格管理")
@RestController
@RequestMapping("/pms/specification")
public class PmsGoodsSpecificationController extends BaseController
{
    @Autowired
    private PmsGoodsSpecificationService pmsGoodsSpecificationService;

    @ApiOperation("查询商品规格列表")
    @PreAuthorize("@ss.hasPermi('pms:specification:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsGoodsSpecificationQueryVo pmsGoodsSpecificationQueryVo)
    {
        startPage();
        List<PmsGoodsSpecification> list = pmsGoodsSpecificationService.selectPmsGoodsSpecificationList(pmsGoodsSpecificationQueryVo);
        return getDataTable(list);
    }

    /**
     * @author 张涛
     * @return
     */
    @ApiOperation("根据id获取商品规格详细信息")
    @Log(title = "商品规格", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('pms:specification:query')")
    @GetMapping(value = "/getSpecificationById/{sid}")
    public TableDataInfo getSpecificationById(@PathVariable("sid") Long sid)
    {
        List<PmsGoodsSpecification> list = (List<PmsGoodsSpecification>) pmsGoodsSpecificationService.selectPmsGoodsSpecificationBySid(sid);
        return getDataTable(list);
    }

    @ApiOperation("导出商品规格列表")
    @Log(title = "商品规格", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('pms:specification:export')")
    @GetMapping("/export")
    public AjaxResult export(PmsGoodsSpecificationQueryVo pmsGoodsSpecificationQueryVo)
    {
        List<PmsGoodsSpecification> list = pmsGoodsSpecificationService.selectPmsGoodsSpecificationList(pmsGoodsSpecificationQueryVo);
        ExcelUtil<PmsGoodsSpecification> util = new ExcelUtil<PmsGoodsSpecification>(PmsGoodsSpecification.class);
        return util.exportExcel(list, "specification");
    }

    @ApiOperation("获取商品规格详细信息")
    @Log(title = "商品规格", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('pms:specification:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pmsGoodsSpecificationService.selectPmsGoodsSpecificationById(id));
    }

    @ApiOperation("新增商品规格")
    @Log(title = "商品规格", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('pms:specification:add')")
    @PostMapping
    public AjaxResult add(@RequestBody PmsGoodsSpecification pmsGoodsSpecification)
    {
        return toAjax(pmsGoodsSpecificationService.insertPmsGoodsSpecification(pmsGoodsSpecification));
    }

    @ApiOperation("修改商品规格")
    @Log(title = "商品规格", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('pms:specification:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody PmsGoodsSpecification pmsGoodsSpecification)
    {
        return toAjax(pmsGoodsSpecificationService.updatePmsGoodsSpecification(pmsGoodsSpecification));
    }

    @ApiOperation("删除商品规格")
    @Log(title = "商品规格", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('pms:specification:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsGoodsSpecificationService.deletePmsGoodsSpecificationByIds(ids));
    }
}
